package com.example.demo.controller;
import com.example.demo.entity.*;

import com.example.demo.mapper.BookMapper;
import com.example.demo.response.RegisterResponse;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BookController {
    @Resource
    BookMapper BookMapper;
    @Autowired
    private BookMapper bookMapper;


    @GetMapping("/getBook")
    public List<Book> getBook(){
        return BookMapper.findAll();
    }

    @PostMapping("/updateUser")
    public RegisterResponse updateUser(@RequestBody User book) {

        BookMapper.updateUser(book);

        return new RegisterResponse(true, "修改成功");
    }



    @PostMapping("/addBook")
    public RegisterResponse register(@RequestBody Book book){

        BookMapper.add(book);
        return new RegisterResponse(true,"添加人员成功");
    }
    @PostMapping("/updateBook")
    public RegisterResponse updateBook(@RequestBody Book book) {

        BookMapper.update(book);
        return new RegisterResponse(true, "更新人员成功");
    }

    @PostMapping("/deleteBook")
    public RegisterResponse deleteBook(@RequestBody Book book) {
        BookMapper.deleteById(book);
        return new RegisterResponse(true, "删除人员成功");
    }

}
